<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            background-color: pink;
        }
    </style>
</head>
<body>
    <script>
        window.addEventListener('load', function() { //load 等页面内容全部加载完毕 可以将js代码放置任意位置
            var div = document.querySelector('div');
            window.addEventListener('resize', function() {
                console.log(window.innerWidth);

                console.log('变化了');
                if (window.innerWidth <= 800) {  // window.innerWidth 获取当前页面窗口的大小
                    div.style.display = 'none';
                } else {
                    div.style.display = 'block';
                }

            }); 
        });
    </script>
    <div></div>
</body>
</html>